package com.heima.kafka.sample;
/*
    
 需求描述：
 @Author: wang
 @Date: 2022/10/18 19:50
 
 */

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class HelloController {
    @Autowired
    private KafkaTemplate kafkaTemplate;

    @GetMapping("/test/hello")
    public String test(){
        List list = new ArrayList<>();
        list.add("你好，kafka");
        kafkaTemplate.send("topic",JSON.toJSONString(list));
        return "success";
    }
}
